﻿using Caliburn.Micro;
using GYMm.UI.ViewModels;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556

namespace GYMm.UI.Views
{
	/// <summary>
	/// An empty page that can be used on its own or navigated to within a Frame.
	/// </summary>
	public sealed partial class StartView : Page
	{
		public StartView()
		{
			this.InitializeComponent();
		}

		/// <summary>
		/// Invoked when this page is about to be displayed in a Frame.
		/// </summary>
		/// <param name="e">Event data that describes how this page was reached.
		/// This parameter is typically used to configure the page.</param>
		protected override void OnNavigatedTo(NavigationEventArgs e)
		{
		}

		private void Button_Click(object sender, RoutedEventArgs e)
		{
			IoC.Get<INavigationService>().NavigateToViewModel<DashboardViewModel>();
		}

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            RotateStoryboard.Begin();

            var sec = 60;
            K1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(sec));
            K2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(sec));
            FillStoryboard.Begin();
        }

        private static Storyboard GetFillSB(Int32 sec, FrameworkElement elementToFill)
        {
            var s = new Storyboard();

            var bla = new DoubleAnimationUsingKeyFrames() { EnableDependentAnimation = true };
            Storyboard.SetTargetProperty(bla, "(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Offset)");
            Storyboard.SetTarget(bla, elementToFill);
            bla.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = new KeyTime(), Value = 1 });
            bla.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(sec)), Value = 0 });

            var bla2 = new DoubleAnimationUsingKeyFrames() { EnableDependentAnimation = true };
            Storyboard.SetTargetProperty(bla2, "(Shape.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Offset)");
            Storyboard.SetTarget(bla2, elementToFill);
            bla2.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = new KeyTime(), Value = 1 });
            bla2.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(sec)), Value = 0 });

            s.Children.Add(bla);
            s.Children.Add(bla2);

            return s;
        }
	}
}
